﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Migrations;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace JobbJakt
{
    /// <summary>
    /// 
    /// </summary>
   public partial class Education
    {
        /// <summary>
        /// 
        /// </summary>
       //public Education(int educationID, string startDate, DateTime endDate, EducationLevel educationLevel, string name, bool examination)
       // {
       //     EducationID = educationID;
       //     StartDate = startDate;
       //     EndDate = endDate;
       //     EducationLevel = educationLevel;
       //     Name = name;
       //     Examination = examination;
       // }
       /// <summary>
       /// Hämtar ut alla utbildningar som ha detta inparameter username
       /// </summary>
       /// <param name="userName"></param>
       /// <returns></returns>
        public static  List<Education> GetEducations(string userName)
        {
           


                var query = JobbJaktDB.Educations
                    .Where(n => n.UserName == userName)
                    .Select(n=>n).ToList();


                return query;
           
                //var listEdu = new List<Education>();
                //listEdu.Add(new Education
                //{
                //    EducationID = 1,
                //    EndDate = DateTime.Now,
                //    EducationLevel = JobbJakt.EducationLevel.Gymnasium,
                //    Examination = true,
                //    Name = "WebClientutveklare",
                //    StartDate = DateTime.Now.ToString(),
                //    UserName = "me"



                //});
                //return listEdu;
            
        }
       /// <summary>
       /// Insert education objekt
       /// </summary>
       /// <param name="education"></param>
       /// <returns></returns>
        public static int InsertEducation(Education education)
        {
            JobbJaktDB.Educations.Add(education);
            int numOFAffectRows = JobbJaktDB.Save();
            return numOFAffectRows;
        }
       /// <summary>
        /// Ta bort education objekt
       /// </summary>
       /// <param name="education"></param>
       /// <returns></returns>
        public static int DeleteEducation(int educationId)
       {
           var query = JobbJaktDB.Educations
               .Where(n => n.EducationID == educationId)
               .Select(n => n).SingleOrDefault();
            JobbJaktDB.Educations.Remove(query);
            return JobbJaktDB.Save();

        }

        public static Education GetEducationObject(int educationId)
        {
            var query = JobbJaktDB.Educations
                .SingleOrDefault(n => n.EducationID == educationId);
            return query;

        }

        /// <summary>
       /// Updatera Utbildning
       /// </summary>
       /// <param name="education"></param>
       /// <returns></returns>
        public static int UpdateEducation(Education education)
        {
            JobbJaktDB.Educations.AddOrUpdate(education);
            return JobbJaktDB.Save();

        }

       


        public  override string ToString()
        {
            return
                string.Format(
                    "Utbildning ID:{0}, Start Datum:{1} Slut Datum:{2} Utbildning Nivå:{3} Utbildning Namn:{4} Examen:{5} Användare Namn:{6}",
                    EducationID, StartDate, EndDate, EducationLevel, Name, Examination, UserName);
        }

    }

 
}
